﻿@using MemoryLoadStatistics.Models
@using MemoryLoadStatistics.Includes

@model List<byte>


@{List<int> indexes = new List<int>();
  for (int i = 0; i <= (int)Count.Seconds * (int)Section.Second; i++)
  {
      indexes.Add(i);
  }
}


<div id="container" style="width: 100%; height: 600px;"></div>

<script type="text/javascript" src="/Scripts/highcharts.js"></script>
<script>
    var chart;
    var options = {
        chart: {
            type:'areaspline',
            zoomType: 'x',
            spacingRight: 20,
            renderTo: 'container',
            events: {
                load: requestData
            }
        },
        title: {
            text: '@this.ViewBag.type Minute stat'
        },
        subtitle: {
            text: document.ontouchstart === undefined ?
                'Click and drag in the plot area to zoom in' :
                'Pinch the chart to zoom in'
        },
        xAxis: {
            categories: [@string.Join(", ", indexes)],
            tickInterval: 2,
            title: {
                text: "Seconds"
            }
        },
        yAxis: {
            title: {
                text: '%'
            },
            min: 0,
            max: 100
        },
        tooltip: {
            shared: true
        },
        legend: {
            enabled: false
        },
        plotOptions: {
            areaspline: {
                fillColor: {
                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
                    stops: [
                        [0, Highcharts.getOptions().colors[0]],
                        [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
                    ]
                },
                lineWidth: 1,
                marker: {
                    enabled: false
                },
                shadow: false,
                states: {
                    hover: {
                        lineWidth: 1
                    }
                },
                threshold: null
            }
        },

        series: [{
            type: 'areaspline',
            pointInterval: @( Math.Round(1.0 / (int)Section.Second, 2).ToString(System.Globalization.NumberFormatInfo.InvariantInfo)),
            name: '%',
            data: [@string.Join(", ", Model)

            ]
        }]
    };

    function requestData() {
        $.ajax({
            url: '@Url.Action("AjaxDisplay", "Stat", new { type = ViewBag.type, displayType = RouterFragments.Stats.MinuteStat })',
            type:'post',
            dataType: "json",
            success: function(points) {
                chart.series[0].setData(eval(points), true,  false);
                setTimeout(requestData, 1000);
            },
            cache: false
        });
    }

    $(document).ready(function() {
        chart = new Highcharts.Chart(options);
    });
</script>
